package com.yinhai.adapter;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yinhai.activity.R;
import com.yinhai.model.ContactsUser;

/**
 * 通讯录点击分组所对应的联系人列表
 * @author Administrator
 *
 */
public class ContactDelContactListAdpter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<ContactsUser> smsList;
	private Date date;
	private SimpleDateFormat sdf;
	private boolean isCheck;

	public ContactDelContactListAdpter(Context context) {
		mInflater = LayoutInflater.from(context);
		this.smsList = new ArrayList<ContactsUser>();
		this.date = new Date();
		this.sdf = new SimpleDateFormat("MM/dd HH:mm");
	}
	public ContactDelContactListAdpter(Context context,List<ContactsUser> smsList,boolean isCheck){
		this(context);
		this.smsList = smsList;
		this.isCheck=isCheck;
	}
	
	public void assignment(List<ContactsUser> smsList) {
		this.smsList = smsList;
	}

	public void add(ContactsUser bean) {
		smsList.add(bean);
	}
	
	public void add(List<ContactsUser> smsList) {
	    smsList.addAll(smsList);
	}

	public void remove(int position) {
		smsList.remove(position);
	}
	
	public void clear() {
		smsList.clear();
	}

	@Override
	public int getCount() {
		return smsList.size();
	}

	@Override
	public Object getItem(int position) {
		return smsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.contact_list_item, parent,
					false);
			holder = new ViewHolder();
			holder.contact_group_name = (TextView) convertView.findViewById(R.id.contact_name1);
			holder.contact_content1 = (TextView) convertView.findViewById(R.id.contact_content1);
			holder.btn_del=(TextView) convertView.findViewById(R.id.btn_del);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.contact_group_name.setText(smsList.get(position).getName());
		holder.contact_content1.setText(smsList.get(position).getTelPhone());
		if(isCheck){
			holder.btn_del.setVisibility(View.VISIBLE);
			holder.btn_del.setTag(position);
			holder.btn_del.setBackgroundResource(R.drawable.ic_dx_sc);
		}
		convertView.setTag(holder);
		return convertView;
	}

	public final class ViewHolder {
		public TextView contact_group_name;
		public TextView contact_content1;
		TextView btn_del;
	}
}
